package com.mtask.task.core.action.impl;


import com.mtask.common.entity.task.TaskJob;
import com.mtask.task.core.action.TaskAction;
import com.mtask.task.repository.TaskJobLogRepository;
import com.mtask.task.service.ActionService;
import lombok.Getter;
import lombok.Setter;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

@Getter
@Setter
public abstract class AbstractTaskAction<T> implements TaskAction {
    protected TaskJob task;
    protected T referenceJob;
    protected TaskJobLogRepository taskJobLogRepository;
    protected JobExecutionContext context;
    protected ActionService actionService;

    public boolean jobNotNull() {
        return referenceJob != null;
    }

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        this.context = context;
        execute();
    }

    public void execute() {
        if (jobNotNull()) {
            beforeStart();
            start();
            afterStart();
        } else {
            //todo
        }
    }
}
